/**
 * Command registration and implementations for GitSummary
 */
const vscode = require('vscode');
const { generateSummary, generateSummaryWithDateRange } = require('./summaryGenerator');

/**
 * Registers all commands for the GitSummary extension
 * @param {vscode.ExtensionContext} context - The extension context
 */
function registerCommands(context) {
  // Register the main summary generation command
  const generateSummaryCommand = vscode.commands.registerCommand(
    'gitsummary.generateSummary',
    async () => {
      try {
        await generateSummary();
      } catch (error) {
        vscode.window.showErrorMessage(`Failed to generate Git summary: ${error.message}`);
        console.error('Error generating summary:', error);
      }
    }
  );
  
  // Register the date-ranged summary command
  const generateDateRangedSummaryCommand = vscode.commands.registerCommand(
    'gitsummary.generateSummaryWithDateRange',
    async () => {
      try {
        await generateSummaryWithDateRange();
      } catch (error) {
        vscode.window.showErrorMessage(`Failed to generate Git summary with date range: ${error.message}`);
        console.error('Error generating date-ranged summary:', error);
      }
    }
  );
  
  // Add commands to subscriptions (important for proper disposal)
  context.subscriptions.push(generateSummaryCommand);
  context.subscriptions.push(generateDateRangedSummaryCommand);
}

module.exports = {
  registerCommands
};
